/*
 * create:2016年4月13日 上午11:10:39
 * author:wangds  
 */
package com.cxkj.shop.biz;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Map;

import javax.servlet.http.HttpSession;

import com.cxkj.shop.form.DefaultDelivery;
import com.cxkj.shop.form.Delivery;
import com.cxkj.shop.model.user.DefaultPostAddress;
import com.cxkj.shop.utils.BusinessUtils;

import net.wangds.comp.business.http.AbstractHttpInteractionBusiness;

/**
 * .
 * @author wangds
 *
 */
public class LoadAddressesBusiness extends AbstractHttpInteractionBusiness<Map<String,Object>, Delivery> {

  /*
   * @see net.wangds.common.processor.Processor#process()
   * @author wangds 2016年4月13日 上午11:11:29.
   */
  @Override
  public void process() {
    DefaultDelivery<Collection<DefaultPostAddress>> res = new DefaultDelivery<Collection<DefaultPostAddress>>();
    
    HttpSession ssn = BusinessUtils.getHttpSessionFromHttpBusiness(this);
    String openId = BusinessUtils.getOpenIdSession(ssn);
    Collection<DefaultPostAddress> addresses = BusinessUtils.loadAddressByOpenId(openId);
    //addresses = _handleEmtpyAddressForTest(addresses);
    res.setData(addresses);
    res.setPostTs(System.currentTimeMillis());
    res.setSuccess(true);
    this.setOutput(res);
  }

  /**
   * .
   * @author wangds 2016年4月14日 下午3:09:50.
   * @param addresses
   * @return
   */
  private Collection<DefaultPostAddress> _handleEmtpyAddressForTest(Collection<DefaultPostAddress> addresses) {
    if(addresses==null||addresses == Collections.EMPTY_LIST){
      addresses = new LinkedList<DefaultPostAddress>();
    }
    if(addresses.size()==0){
      DefaultPostAddress add=new DefaultPostAddress();
      add.setAddId("tmp0");
      add.setAddress("沈阳市铁西区霁虹街道鑫丰国际6号楼17B层2室");
      add.setLastUseTm(System.currentTimeMillis());
      add.setOpenId("abc");
      add.setPhone("18604039593");
      add.setPostCode("110000");
      add.setReceiverName("王东石");
      add.setDefaultAdd(true);
      addresses.add(add);
      add=new DefaultPostAddress();
      add.setAddId("tmp1");
      add.setAddress("沈阳市铁西区霁虹街道鑫丰国际6号楼17B层2室");
      add.setLastUseTm(System.currentTimeMillis());
      add.setOpenId("abc");
      add.setPhone("18604039593");
      add.setPostCode("110000");
      add.setReceiverName("王东石1");
      add.setDefaultAdd(false);
      addresses.add(add);
    }
    return addresses;
  }

}
